package com.bwie.common.handler;

import com.bwie.common.exceptions.SendCodeException;
import com.bwie.common.exceptions.ServiceException;
import com.bwie.common.exceptions.TelLoginException;
import com.bwie.common.constants.Constants;
import com.bwie.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName:
 * @Description:  全局异常处理
 * @Author: zhuwenqiang
 * @Date: 2024/6/21
 */
@RestControllerAdvice
@Log4j2
public class GlobalExceptionHandler {

    /**
     * 处理发送验证码异常
     */
    @ExceptionHandler(SendCodeException.class)
    public Result sendCodeExceptionHandler(SendCodeException exception) {
        log.error("发送验证码异常，异常信息：{}", exception.getMessage());
        return Result.error(Constants.ERROR, exception.getMessage());
    }

    /**
     * 处理发送验证码异常
     */
    @ExceptionHandler(TelLoginException.class)
    public Result telLoginExceptionHandler(TelLoginException exception) {
        log.error("短信验证码登录异常，异常信息：{}", exception.getMessage());
        return Result.error(Constants.ERROR, exception.getMessage());
    }

    /**
     * 处理业务异常
     */
    @ExceptionHandler(ServiceException.class)
    public Result serviceExceptionHandler(ServiceException exception) {
        log.error("业务异常，异常信息：{}", exception.getMessage());
        return Result.error(Constants.ERROR, exception.getMessage());
    }

}
